<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <input type="text" class="user">
    <br>
    <input type="text" class="pwd">
    <br>
    <button>登录</button>


    <script src="../js/tools.js"></script>
    <script src="../js/ajax.js"></script>
    <script src="../js/cookie.js"></script>
    <script>

        const oUser = get('.user');
        const oPwd = get('.pwd');
        const oBtn = get('button');


        oBtn.onclick = function () {
            const username = oUser.value;
            const password = oPwd.value;

            ajax({
                path: `../php/06login.php?username=${username}&password=${password}`,
                success: data => {
                    console.log(data);
                    const { status, msg } = data;
                    if (status) {
                        // 成功就跳转了
                        alert('登录成功');
                        // 记录是谁登录 了
                        // setCookie('who', username);
                        localStorage.setItem('LOGIN_USER', username);

                        // 切割地址栏
                        const historyURL = location.search.replace('?HISTORY=', '');
                        console.log(historyURL);

                        // 从哪里来，就回哪里去
                        if (historyURL) {
                            location.href = historyURL;
                        } else {
                            // 默认进入商品列表页
                            location.href = './03list.html';
                        }


                    } else {
                        alert(msg);
                    }
                }
            })
        }




    </script>

</body>

</html>